//
//  ATVInstanceService.m
//  FlashController
//
//  Created by Martin Schiøth Dyrby on 11/15/11.
//  Copyright 2011 Molamil. All rights reserved.
//

#import "ATVInstanceService.h"
#import "ATVInstance.h"

@implementation ATVInstanceService
@synthesize instances;
@synthesize asTypeParser;
- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
        instances = [[NSMutableArray alloc] init];
        
        
    }
    
    return self;
}

- (void)dealloc
{
    [instances release];
    [super dealloc];
}

- (void) cleanAll {
    [instances removeAllObjects];
}


- (void) addInstanceFromXMLString: (NSString *) xml
{
	[asTypeParser parseData: [xml dataUsingEncoding: NSUTF8StringEncoding]];
    
    ATVInstance *instance = [[ATVInstance alloc] init];
    instance.path = asTypeParser.path;
    instance.items = [asTypeParser parseItems]; 
    
    [instances addObject:instance];
}

- (void) removeInstanceWithPath: (NSString *) path {

    
    NSUInteger count = [instances count];
    while (count--) {
        ATVInstance *instance = [instances objectAtIndex:count];
        if([instance.path isEqualToString:path]) {
            [instances removeObjectAtIndex:count];
            [instance release];
            break;
        }
    }
}

- (ATVInstance *) getInstanceAtIndex: (NSInteger) index {
    return [instances objectAtIndex:index];
}


@end
